package org.leiyang.gateway.config;

import org.leiyang.gateway.handler.ChooseIdleMsgServerHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;

/**
 * 路由配置信息
 */
@Configuration
public class RouterFunctionConfiguration {
    @Autowired
    private ChooseIdleMsgServerHandler chooseIdleMsgServerHandler;

    /**
     * 拦截/server/choose请求，直接由ChooseIdleMsgServerHandler处理返回
     */
    @SuppressWarnings("rawtypes")
    @Bean
    public RouterFunction routerFunction() {
        return RouterFunctions.route(
                RequestPredicates.GET("/server/choose").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
                chooseIdleMsgServerHandler);
    }
}